//
//  OfferTableViewCell.m
//  EggSteward
//
//  Created by 王道林 on 16/9/12.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "OfferTableViewCell.h"
#import "Masonry.h"
#import "BaseLabel.h"
#import "BaseButton.h"
#import "OfferEggModel.h"
@interface OfferTableViewCell ()
@property (nonatomic, strong)BaseLabel *labelDate;
@property (nonatomic, strong)BaseLabel *labelPlace;
@property (nonatomic, strong)BaseLabel *labelPrice;
@property (nonatomic, strong)BaseButton *buttonOperate;
@end
@implementation OfferTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}

- (void)createSubview
{
    _labelDate = [[BaseLabel alloc] init];
    _labelDate.text = @"记录日期";
    [self.contentView addSubview:_labelDate];
    
    _labelPlace = [[BaseLabel alloc] init];
    _labelPlace.text = @"地区";
    [self.contentView addSubview:_labelPlace];
    
    _labelPrice = [[BaseLabel alloc] init];
    _labelPrice.text = @"价格";
    [self.contentView addSubview:_labelPrice];
    
    _buttonOperate = [BaseButton buttonWithType:UIButtonTypeCustom];
    [_buttonOperate setImage:[UIImage imageNamed:@"Unknown-1"] forState:UIControlStateNormal];
    [self.contentView addSubview:_buttonOperate];
    [_buttonOperate addTarget:self action:@selector(buttonOperateAction:) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    [_labelDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).mas_offset(5);
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.25);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_equalTo(-5);
    }];
    
    [_labelPlace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).mas_offset(5);
        make.left.mas_equalTo(_labelDate.mas_right).mas_offset(20);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.15);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_equalTo(-5);
    }];
    
    [_labelPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).mas_offset(5);
        make.left.mas_equalTo(_labelPlace.mas_right).mas_offset(40);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.15);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_equalTo(-5);
    }];
    
    [_buttonOperate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).mas_offset(5);
        make.left.mas_equalTo(_labelPrice.mas_right).mas_offset(30);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.11);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_equalTo(-5);
    }];

}
- (void)setModel:(OfferEggModel *)model
{
    _model = model;
    _labelDate.text = _model.NoteDate;
    _labelPlace.text = _model.Province;
    _labelPrice.text = _model.EggSalePrice;
}

#pragma mark -点击操作
- (void)buttonOperateAction:(BaseButton *)button
{
    self.blockButton(_model);
}


@end
